﻿// See https://aka.ms/new-console-template for more information
using System;
using System.ComponentModel.Design;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Xml.Schema;

Console.ReadKey();
Console.WriteLine("Hello, World!");

// var coreAssemblyInfo = FileVersionInfo.GetVersionInfo(typeof(object).Assembly.Location);
// Console.WriteLine($"Core Runtime Info: {coreAssemblyInfo.ProductVersion}");
// Console.WriteLine($"System.Private.CoreLib.dll is located at: {typeof(object).Assembly.Location}");

GC.GetGCMemoryInfo(GCKind.Any);
GC.GetTotalMemory(true);




Console.WriteLine("press any key to continue");


var rand = new Random();
int allocMax = 128;
int len = 256;
var l = new List<int>[len];

while(true)
{
    Console.WriteLine("hello malloc and free");
    int needNeed = rand.Next(0,3);

    if (needNeed == 1)
        helloEnd();
    else if (needNeed == 2)
        hello2();
    else
        hello();

    var a = rand.Next(1,allocMax);
    var n = rand.Next(1,len);
    l[n] = new List<int>(a);
    Thread.Sleep(3000);
}

Thread.Sleep(999999999);

Console.WriteLine("Hello, World Exit");

//Cdecl表示C语言格式导出的函数， EntryPoint 指定导出函数的函数名
//Add1 如果没有指定EntryPoint，则必须与导出函数名一致
[DllImport("hi", EntryPoint = "hello", CallingConvention = CallingConvention.Cdecl)]
static extern void hello();  

[DllImport("hi", EntryPoint = "hello2", CallingConvention = CallingConvention.Cdecl)]
static extern void hello2();  

[DllImport("hi", EntryPoint = "helloEnd", CallingConvention = CallingConvention.Cdecl)]
static extern void helloEnd(); 